package classes.Commands
{
	import UIUtils.uif_util;
	
	import classes.c_events;
	
	import components.editor.c_baseEditor;
	import components.editor.c_bitmapElement;
	
	import flash.display.Bitmap;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class c_mergeToBitmap extends c_deleteAll {
		private var _index			: int;
		public function c_mergeToBitmap(a_editor: c_baseEditor) {
			super(a_editor);
		}
		
		override public function Execute():void {
			var bmp		: Bitmap;
			var rect	: Rectangle;
			if (!_element) {
				rect 	= editor.allRect();
				bmp 	= new Bitmap(editor.paintFromBitmap(true));
			}
			
			super.Execute();
			
			if (!_element) {
				_element = new c_bitmapElement(editor.imageLayer, rect, bmp);
				_index = _element.index;
			} else {
				_element.setParent(editor.imageLayer, _index);
			}
			editor.dragRect.link = _element;
		}
		
		override public function unExecute():void {
			_element.remove();
			super.unExecute();
		}
		
		override public function dispose():void {
			_element.dispose();
		}
	}
}